package com.lemon.main;

import com.lemon.constant.Constant;
import com.lemon.service.SendDataThread;
import com.lemon.service.ShutDownHookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.Properties;

public class MainClass {
    private static final Logger logger = LoggerFactory.getLogger(MainClass.class);
    public static void main(String[] args) {
        try {
            initConfig();
            Thread sendThread = new Thread(new SendDataThread());
            sendThread.setDaemon(false);
            sendThread.start();
            Runtime.getRuntime().addShutdownHook(new Thread(new ShutDownHookService()));
        } catch (Exception e){
            logger.error("probe start fail.", e);
            System.exit(500);
        }
    }

    private static void initConfig() throws IOException {
        InputStreamReader inputStreamReader = new InputStreamReader(
                MainClass.class
                .getClassLoader()
                .getResourceAsStream("config.properties"));
        Properties properties = new Properties();
        properties.load(inputStreamReader);
        Constant.serviceAdd = (String) properties.get("service.address");
    }
}